<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="默认碳含量" prop="sb1">
        <el-input
          v-model="queryParams.sb1"
          placeholder="请输入默认碳含量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="默认氧化率 Default Oxidation Rate" prop="sb2">
        <el-input
          v-model="queryParams.sb2"
          placeholder="请输入默认氧化率 Default Oxidation Rate"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="默认低位发热值 " prop="sb3">
        <el-input
          v-model="queryParams.sb3"
          placeholder="请输入默认低位发热值 "
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="默认燃料重量或体积的排放系数 " prop="sb4">
        <el-input
          v-model="queryParams.sb4"
          placeholder="请输入默认燃料重量或体积的排放系数 "
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="燃料 Fuel" prop="sb5">
        <el-input
          v-model="queryParams.sb5"
          placeholder="请输入燃料 Fuel"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="能源行业甲烷系数 CH4 EF for Energy Industry " prop="sb6">
        <el-input
          v-model="queryParams.sb6"
          placeholder="请输入能源行业甲烷系数 CH4 EF for Energy Industry "
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="建筑行业甲烷系数 CH4 EF for Manufacturing Industries and Construction" prop="sb7">
        <el-input
          v-model="queryParams.sb7"
          placeholder="请输入建筑行业甲烷系数 CH4 EF for Manufacturing Industries and Construction"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制造业甲烷系数 CH4 EF for Manufacturing Industries" prop="sb8">
        <el-input
          v-model="queryParams.sb8"
          placeholder="请输入制造业甲烷系数 CH4 EF for Manufacturing Industries"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商业甲烷系数 CH4 EF for Commercial" prop="sb9">
        <el-input
          v-model="queryParams.sb9"
          placeholder="请输入商业甲烷系数 CH4 EF for Commercial"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构甲烷系数 CH4 EF for  Institutional Sectors Category" prop="sb10">
        <el-input
          v-model="queryParams.sb10"
          placeholder="请输入机构甲烷系数 CH4 EF for  Institutional Sectors Category"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="住宅 CH4 EF for Residential" prop="sb11">
        <el-input
          v-model="queryParams.sb11"
          placeholder="请输入住宅 CH4 EF for Residential"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="农业 CH4 EF for Agriculture" prop="sb12">
        <el-input
          v-model="queryParams.sb12"
          placeholder="请输入农业 CH4 EF for Agriculture"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="林业 CH4 EF for Forestry" prop="sb13">
        <el-input
          v-model="queryParams.sb13"
          placeholder="请输入林业 CH4 EF for Forestry"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="渔业/渔场 CH4 EF for Fishing/Fishing Farms SectorsCategories" prop="sb14">
        <el-input
          v-model="queryParams.sb14"
          placeholder="请输入渔业/渔场 CH4 EF for Fishing/Fishing Farms SectorsCategories"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="能源行业N2O系数 N2O EF for Energy Industry " prop="sb15">
        <el-input
          v-model="queryParams.sb15"
          placeholder="请输入能源行业N2O系数 N2O EF for Energy Industry "
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction" prop="sb16">
        <el-input
          v-model="queryParams.sb16"
          placeholder="请输入建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction" prop="sb17">
        <el-input
          v-model="queryParams.sb17"
          placeholder="请输入建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category" prop="sb18">
        <el-input
          v-model="queryParams.sb18"
          placeholder="请输入商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category" prop="sb19">
        <el-input
          v-model="queryParams.sb19"
          placeholder="请输入商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="住宅和农业/林业/渔业/渔场N2O系数 N2O EF for Residential and, Agriculture/Forestry/Fishing/Fishing Farms SectorsCategories" prop="sb20">
        <el-input
          v-model="queryParams.sb20"
          placeholder="请输入住宅和农业/林业/渔业/渔场N2O系数 N2O EF for Residential and, Agriculture/Forestry/Fishing/Fishing Farms SectorsCategories"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['busi:companyEf:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['busi:companyEf:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['busi:companyEf:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['busi:companyEf:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="companyEfList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" v-if="false"/>
      <el-table-column label="默认碳含量" align="center" prop="sb1" />
      <el-table-column label="默认氧化率 Default Oxidation Rate" align="center" prop="sb2" />
      <el-table-column label="默认低位发热值 " align="center" prop="sb3" />
      <el-table-column label="默认燃料重量或体积的排放系数 " align="center" prop="sb4" />
      <el-table-column label="燃料 Fuel" align="center" prop="sb5" />
      <el-table-column label="能源行业甲烷系数 CH4 EF for Energy Industry " align="center" prop="sb6" />
      <el-table-column label="建筑行业甲烷系数 CH4 EF for Manufacturing Industries and Construction"" align="center" prop="sb7" />
      <el-table-column label="制造业甲烷系数 CH4 EF for Manufacturing Industries" align="center" prop="sb8" />
      <el-table-column label="商业甲烷系数 CH4 EF for Commercial" align="center" prop="sb9" />
      <el-table-column label="机构甲烷系数 CH4 EF for  Institutional Sectors Category" align="center" prop="sb10" />
      <el-table-column label="住宅 CH4 EF for Residential" align="center" prop="sb11" />
      <el-table-column label="农业 CH4 EF for Agriculture" align="center" prop="sb12" />
      <el-table-column label="林业 CH4 EF for Forestry" align="center" prop="sb13" />
      <el-table-column label="渔业/渔场 CH4 EF for Fishing/Fishing Farms SectorsCategories" align="center" prop="sb14" />
      <el-table-column label="能源行业N2O系数 N2O EF for Energy Industry " align="center" prop="sb15" />
      <el-table-column label="建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction" align="center" prop="sb16" />
      <el-table-column label="建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction" align="center" prop="sb17" />
      <el-table-column label="商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category" align="center" prop="sb18" />
      <el-table-column label="商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category" align="center" prop="sb19" />
      <el-table-column label="住宅和农业/林业/渔业/渔场N2O系数 N2O EF for Residential and, Agriculture/Forestry/Fishing/Fishing Farms SectorsCategories" align="center" prop="sb20" />
      <el-table-column label="操作" width="155" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['busi:companyEf:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['busi:companyEf:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改碳排放对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1100px" height="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="280px">
        <el-form-item label="默认碳含量" prop="sb1">
          <el-input v-model="form.sb1" placeholder="请输入默认碳含量" />
        </el-form-item>
        <el-form-item label="默认氧化率 Default Oxidation Rate" prop="sb2">
          <el-input v-model="form.sb2" placeholder="请输入默认氧化率 Default Oxidation Rate" />
        </el-form-item>
        <el-form-item label="默认低位发热值 " prop="sb3">
          <el-input v-model="form.sb3" placeholder="请输入默认低位发热值 " />
        </el-form-item>
        <el-form-item label="默认燃料重量或体积的排放系数 " prop="sb4">
          <el-input v-model="form.sb4" placeholder="请输入默认燃料重量或体积的排放系数 " />
        </el-form-item>
        <el-form-item label="燃料 Fuel" prop="sb5">
          <el-input v-model="form.sb5" placeholder="请输入燃料 Fuel" />
        </el-form-item>
        <el-form-item label="能源行业甲烷系数 CH4 EF for Energy Industry " prop="sb6">
          <el-input v-model="form.sb6" placeholder="请输入能源行业甲烷系数 CH4 EF for Energy Industry " />
        </el-form-item>
        <el-form-item label="建筑行业甲烷系数 CH4 EF for Manufacturing Industries and Construction" prop="sb7">
          <el-input v-model="form.sb7" placeholder="请输入建筑行业甲烷系数 CH4 EF for Manufacturing Industries and Construction" />
        </el-form-item>
        <el-form-item label="制造业甲烷系数 CH4 EF for Manufacturing Industries" prop="sb8">
          <el-input v-model="form.sb8" placeholder="请输入制造业甲烷系数 CH4 EF for Manufacturing Industries" />
        </el-form-item>
        <el-form-item label="商业甲烷系数 CH4 EF for Commercial" prop="sb9">
          <el-input v-model="form.sb9" placeholder="请输入商业甲烷系数 CH4 EF for Commercial" />
        </el-form-item>
        <el-form-item label="机构甲烷系数 CH4 EF for  Institutional Sectors Category" prop="sb10">
          <el-input v-model="form.sb10" placeholder="请输入机构甲烷系数 CH4 EF for  Institutional Sectors Category" />
        </el-form-item>
        <el-form-item label="住宅 CH4 EF for Residential" prop="sb11">
          <el-input v-model="form.sb11" placeholder="请输入住宅 CH4 EF for Residential" />
        </el-form-item>
        <el-form-item label="农业 CH4 EF for Agriculture" prop="sb12">
          <el-input v-model="form.sb12" placeholder="请输入农业 CH4 EF for Agriculture" />
        </el-form-item>
        <el-form-item label="林业 CH4 EF for Forestry" prop="sb13">
          <el-input v-model="form.sb13" placeholder="请输入林业 CH4 EF for Forestry" />
        </el-form-item>
        <el-form-item label="渔业/渔场 CH4 EF for Fishing/Fishing Farms SectorsCategories" prop="sb14">
          <el-input v-model="form.sb14" placeholder="请输入渔业/渔场 CH4 EF for Fishing/Fishing Farms SectorsCategories" />
        </el-form-item>
        <el-form-item label="能源行业N2O系数 N2O EF for Energy Industry " prop="sb15">
          <el-input v-model="form.sb15" placeholder="请输入能源行业N2O系数 N2O EF for Energy Industry " />
        </el-form-item>
        <el-form-item label="建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction" prop="sb16">
          <el-input v-model="form.sb16" placeholder="请输入建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction" />
        </el-form-item>
        <el-form-item label="建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction" prop="sb17">
          <el-input v-model="form.sb17" placeholder="请输入建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction" />
        </el-form-item>
        <el-form-item label="商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category" prop="sb18">
          <el-input v-model="form.sb18" placeholder="请输入商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category" />
        </el-form-item>
        <el-form-item label="商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category" prop="sb19">
          <el-input v-model="form.sb19" placeholder="请输入商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category" />
        </el-form-item>
        <el-form-item label="住宅和农业/林业/渔业/渔场N2O系数 N2O EF for Residential and, Agriculture/Forestry/Fishing/Fishing Farms SectorsCategories" prop="sb20">
          <el-input v-model="form.sb20" placeholder="请输入住宅和农业/林业/渔业/渔场N2O系数 N2O EF for Residential and, Agriculture/Forestry/Fishing/Fishing Farms SectorsCategories" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCompanyEf, getCompanyEf, delCompanyEf, addCompanyEf, updateCompanyEf } from "@/api/busi/companyEf";

export default {
  name: "CompanyEf",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 碳排放表格数据
      companyEfList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sb1: undefined,
        sb2: undefined,
        sb3: undefined,
        sb4: undefined,
        sb5: undefined,
        sb6: undefined,
        sb7: undefined,
        sb8: undefined,
        sb9: undefined,
        sb10: undefined,
        sb11: undefined,
        sb12: undefined,
        sb13: undefined,
        sb14: undefined,
        sb15: undefined,
        sb16: undefined,
        sb17: undefined,
        sb18: undefined,
        sb19: undefined,
        sb20: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: false, message: "不能为空", trigger: "blur" }
        ],
        sb1: [
          { required: false, message: "默认碳含量不能为空", trigger: "blur" }
        ],
        sb2: [
          { required: false, message: "默认氧化率 Default Oxidation Rate不能为空", trigger: "blur" }
        ],
        sb3: [
          { required: false, message: "默认低位发热值 不能为空", trigger: "blur" }
        ],
        sb4: [
          { required: false, message: "默认燃料重量或体积的排放系数 不能为空", trigger: "blur" }
        ],
        sb5: [
          { required: false, message: "燃料 Fuel不能为空", trigger: "blur" }
        ],
        sb6: [
          { required: false, message: "能源行业甲烷系数 CH4 EF for Energy Industry 不能为空", trigger: "blur" }
        ],
        sb7: [
          { required: false, message: "建筑行业甲烷系数 CH4 EF for Manufacturing Industries and Construction不能为空", trigger: "blur" }
        ],
        sb8: [
          { required: false, message: "制造业甲烷系数 CH4 EF for Manufacturing Industries不能为空", trigger: "blur" }
        ],
        sb9: [
          { required: false, message: "商业甲烷系数 CH4 EF for Commercial不能为空", trigger: "blur" }
        ],
        sb10: [
          { required: false, message: "机构甲烷系数 CH4 EF for  Institutional Sectors Category不能为空", trigger: "blur" }
        ],
        sb11: [
          { required: false, message: "住宅 CH4 EF for Residential不能为空", trigger: "blur" }
        ],
        sb12: [
          { required: false, message: "农业 CH4 EF for Agriculture不能为空", trigger: "blur" }
        ],
        sb13: [
          { required: false, message: "林业 CH4 EF for Forestry不能为空", trigger: "blur" }
        ],
        sb14: [
          { required: false, message: "渔业/渔场 CH4 EF for Fishing/Fishing Farms SectorsCategories不能为空", trigger: "blur" }
        ],
        sb15: [
          { required: false, message: "能源行业N2O系数 N2O EF for Energy Industry 不能为空", trigger: "blur" }
        ],
        sb16: [
          { required: false, message: "建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction不能为空", trigger: "blur" }
        ],
        sb17: [
          { required: false, message: "建筑行业N2O系数 N2O EF for Manufacturing Industries and Construction不能为空", trigger: "blur" }
        ],
        sb18: [
          { required: false, message: "商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category不能为空", trigger: "blur" }
        ],
        sb19: [
          { required: false, message: "商业和机构N2O系数 N2O EF for MCommercial and Institutional Sectors Category不能为空", trigger: "blur" }
        ],
        sb20: [
          { required: false, message: "住宅和农业/林业/渔业/渔场N2O系数 N2O EF for Residential and, Agriculture/Forestry/Fishing/Fishing Farms SectorsCategories不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询碳排放列表 */
    getList() {
      this.loading = true;
      listCompanyEf(this.queryParams).then(response => {
        this.companyEfList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        sb1: undefined,
        sb2: undefined,
        sb3: undefined,
        sb4: undefined,
        sb5: undefined,
        sb6: undefined,
        sb7: undefined,
        sb8: undefined,
        sb9: undefined,
        sb10: undefined,
        sb11: undefined,
        sb12: undefined,
        sb13: undefined,
        sb14: undefined,
        sb15: undefined,
        sb16: undefined,
        sb17: undefined,
        sb18: undefined,
        sb19: undefined,
        sb20: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加碳排放";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getCompanyEf(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改碳排放";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateCompanyEf(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addCompanyEf(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除碳排放编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delCompanyEf(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
        this.$download.excel('/busi/companyEf/export', this.queryParams);
    }
  }
};
</script>

